--回流
local huiliu = fk.CreateSkill {
    name = "mcdh_huiliu"
}
local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

huiliu:addEffect('viewas',{
    pattern = "slash,jink",
    card_filter = Util.FalseFunc,
    interaction = function(self)
        local names = {}
        for _, name in ipairs({ "slash", "jink" }) do
            local card = Fk:cloneCard(name)
            if (Fk.currentResponsePattern == nil ) or
                    (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)) then
                table.insertIfNeed(names, card.name)
            end
        end
        if #names == 0 then return end
        return UI.ComboBox { choices = names }
    end,
    view_as = function(self, cards)
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = self.name
        return card
    end,
    enabled_at_play = function(self, player)
        if player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and not player:isKongcheng() then
            local card = Fk:getCardById(player:getCardIds("h")[1])
            return table.every(player:getCardIds("h"), function(id) return Fk:getCardById(id).suit == card.suit end)
        end
    end,
    enabled_at_response = function(self, player, response)
        if not response and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and not player:isKongcheng() then
            local card = Fk:getCardById(player:getCardIds("h")[1])
            return table.every(player:getCardIds("h"), function(id) return Fk:getCardById(id).suit == card.suit end)
        end
    end,
    before_use = function(self, player, use)
        use.extraUse = true
    end,
    after_use = function(self, player, use)
        if not player.dead then
            player:drawCards(1, self.name)
        end
    end
})

huiliu:addEffect('targetmod',{
    bypass_times =function (self, player, skill, scope, card, to)
        if card then
            return table.contains(card.skillNames,"mcdh_huiliu")
        end
    end,
})

Fk:loadTranslationTable {
    ["mcdh_huiliu"] = "回流",
    [":mcdh_huiliu"] = "每回合限一次，当你需要使用【杀】或【闪】时，若你的手牌只包含一种花色，你可以展示手牌，视为使用一张不计入次数的【杀】或【闪】并摸一张牌。"
}

return huiliu